package com.lyl.momanapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lyl.momanapp.R;
import com.lyl.momanapp.bean.StorseBean;

import java.util.ArrayList;

import static com.lyl.momanapp.bean.URL.storesname;

/**
 * 名字 梁亚龙
 * 时间 2017/12/4.
 * QQ邮箱 503934353@qq.com
 */

public class StoresAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private Context context;
    private ArrayList<StorseBean.DataBean> list;

    public StoresAdapter(Context context, ArrayList<StorseBean.DataBean> list) {
        this.mInflater = LayoutInflater.from(context);
        this.context=context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final StorseBean.DataBean dataBean = list.get(position);
        StoresAdapter.ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new StoresAdapter.ViewHolder();
            convertView = mInflater.inflate(R.layout.item_stores, null);
            viewHolder.name = convertView.findViewById(R.id.stores_name);

            viewHolder.add = convertView.findViewById(R.id.stores_add);

            viewHolder.img = convertView.findViewById(R.id.stores_img);
            convertView.setTag(dataBean);

        } else {
            viewHolder = (StoresAdapter.ViewHolder) convertView.getTag();
        }
        viewHolder.name.setText(dataBean.getStore_name());
        viewHolder.add.setText(dataBean.getAddress());
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                storesname=dataBean.getStore_name();
                mOnItemClickLitener.onItemClick();
            }
        });

        return convertView;

    }

    class ViewHolder {
        private ImageView img;
        private TextView name, add, shop, num;

    }
    public interface OnItemClickLitener {
        void onItemClick();
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }
}
